Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Extend BEFORE/AFTER to accept epoch ms and ISO strings so the now accessor works, and add evaluation coverage for locked time.
Share one evaluation timestamp across standalone flag() and evaluate() calls keyed by the same request identity as identify caching.
Collaborator
Author
|
Change of plans. An app can do We're adding general support for timestamp based dates to the Vercel Flags UI, so the current date works just like updatedAt, createdAt timestamps etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
This PR adds explicit time support to flag evaluation. It adds a
nowvalue. Thenowvalue is the current time in epoch milliseconds.Why we need this
Some flags use time-based conditions. Some flags use time-based rollouts. Before this PR, the code read the time with
Date.now()at each check. Different flags in the same request could read different times. This PR fixes that problem.How it works
nowvalue at the start.nowvalue.nowvalue.nowthroughdecide()andbulkDecide().nowthroughevaluate()andbulkEvaluate().nowas a parameter. Adapters do not need to callDate.now()themselves.New condition type
nowaccessor for conditions.Changed files
packages/flags/src/types.ts: Addsnowto theDecideandAdaptertypes.packages/flags/src/next/evaluate.ts: Locksnowonce per batch. Passesnowto each flag.packages/flags/src/sveltekit/index.ts: Locksnowonce per request context. Passesnowto each flag.packages/adapter-vercel/src/index.ts: Passesnowtoevaluate()andbulkEvaluate().packages/vercel-flags-core/src/types.ts: Adds thenowfield toEvaluationParams. Adds theNOWaccessor type.packages/vercel-flags-core/src/evaluate.ts: ReadsnowfromEvaluationParamsinstead of callingDate.now(). Usesnowfor rollout timing and for the newnowaccessor.packages/vercel-flags-core/src/controller-fns.tsandcreate-raw-client.ts: Add anoptionsparameter withnow. Default to the evaluation start time when the caller does not passnow.nowvalue.Backward compatibility
nowoption is optional at the client API level.now, the code falls back to the evaluation start time.